package com.east.service.impl;

import cn.hutool.core.lang.hash.Hash;
import cn.hutool.db.handler.HandleHelper;
import com.east.dto.DicValueDTO;
import com.east.manager.CustomCache;
import com.east.mapper.DicValueMapper;
import com.east.result.Result;
import com.east.service.DicValueService;
import com.east.utils.Constants;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DicValueServiceImpl implements DicValueService {
    @Resource
    private DicValueMapper dicValueMapper;

    @Override
    public Result getTypeValueAndId(String typeCode) {
        ArrayList<HashMap<String, String>> list = new ArrayList<>();
        System.out.println(typeCode);
        List<DicValueDTO> dicValueDTOS = (List<DicValueDTO>) CustomCache.CACHE.getIfPresent(Constants.CACHE_DIC_VALUE);
        dicValueDTOS.forEach(dicValueDTO -> {
            if (typeCode.equals(dicValueDTO.getTypeCode())) {
                HashMap<String, String> map = new HashMap<>();
                map.put("id",dicValueDTO.getId()+"");
                map.put("name",dicValueDTO.getTypeValue());
                list.add(map);
            }
        });
        return Result.OK(list);
    }
}
